//新增地址
$('.add-btn').click(function(){
    var coinId = $('.coin-option:selected').data('id');
    var coinName = $('.coin-option:selected').html();
    var remark = $('.remark').val();
    var address = $('.coin-address').val();
    var data1 = {
        coinId:coinId,
        remark:remark,
        address:address
    };
    if(!address){
        $('.err-info').html('请填写您的提币地址');
    }else{
        $.ajax({
            url:'/withdraw-validateaddress.json',
            type:'get',
            data:{
                coinName: coinName,
                address:address,
                coinId:coinId
            },
            dataType:'json',
            contentType:'application/json;charset=UTF-8',
            success:function(data){
                if(data.isvalid==false){
                    $('.err-info').html('您的提币地址不正确，请确认后再次输入');
                }else{
                    $.ajax({
                        url:'withdraw-address.json',
                        type:'post',
                        data:JSON.stringify(data1),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        success:function(){
                            $('.err-info').html('添加成功！刷新本页后可在下方列表中查看您添加的地址');
                            setTimeout(function(){
                                location.reload();
                            },200);
                        },
                        error:function(err){
                            $('.err-info').html(JSON.parse(err.responseText).errors[0].msg);
                        }
                    })
                }
            },
            error:function(err){
                $('.err-info').html(JSON.parse(err.responseText).errors[0].msg);
            }
        });

    }


});
//删除地址
$('.delete').click(function(){
    var id = $(this).data('id');
    $.ajax({
        url:'withdraw-address.json?id='+id,
        type:'delete',
        dataType:'json',
        contentType:'application/json;charset=UTF-8',
        success:function(){
            $('.err-info').html('删除成功！请勿重复删除');
            setTimeout(function(){
                location.reload();
            },200);

        },
        error:function(err){
            $('.err-info').html(JSON.parse(err.responseText).errors[0].msg);
        }

    })
});